function plot_hmm( S )

hmm=S.hmm;
block=S.block;
tres=S.tres;
Apca=S.Apca;

NK=S.NK;

figure; hold on;
for ii=1:NK,
    ts=tres:tres:length(block(1).q_star)*tres;
    %ts=tres:tres:size(xin,2)*tres;        
    %ts=ts(delta*(M-1)+1:end);
    plot(ts,(block(1).q_star==ii)+2*(ii) ,'b');
    xlabel('time(s)');
end;

figure;
for ii=1:NK,

    cv=Apca*hmm.state(ii).Cov*Apca';
    subplot(NK,1,ii); imagesc(abs(cv)); colorbar; 
%        subplot(NK,1,(ii-1)*2+2); imagesc(abs(hmm.state(ii).Mu), [0 1]); colorbar; 

end;


StatePath = block(1).q_star;
%StatePath = simdata.Xclass(1:Nto);
NumberOccurences = zeros(1,hmm.K);
FractionalOccupancy = zeros(1,hmm.K);
MeanLifeTime = zeros(1,hmm.K);

for ctr = 1:hmm.K
    temp = StatePath == ctr;
    NumberOccurences(ctr) = sum(diff(temp) == 1);
    FractionalOccupancy(ctr) = sum(temp)/length(temp); 
    MeanLifeTime(ctr) = sum(temp)/NumberOccurences(ctr);
end
x=1:NK;

% plots
figure;
subplot(121);bar(x,FractionalOccupancy);
plot4paper('State #','Fractional occupancy');

subplot(122);bar(x,(tres)*MeanLifeTime);
plot4paper('State #','Mean life time (s)');



end

